package org.zyzboole.base.encrypt.crypto.encryption;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.zyzboole.base.encrypt.crypto.RsaKit;

/**
 * @Author: zyz
 * @Date: 2022/2/14 15:14
 * @description
 */
@Component
public class RSA implements EncryptDispose {

    private static class SingletonHolder {
        private static final RSA INSTANCE = new RSA();
    }

    private RSA() {
    }

    public static final RSA getInstance() {
        return SingletonHolder.INSTANCE;
    }

    @Autowired
    private RsaKit rsaKit;

    @Override
    public String encrypt(String text) {
        try {
            return rsaKit.encrypt(text);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String decrypt(String encryptStr) {
        try {
            return rsaKit.decrypt(encryptStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
